import { observer } from 'mobx-react'
import styles from './index.module.less'
import store from '../../store'
import { resumeTypeMap } from '@/const'
import { formateMoney } from '@/utils'
import { deleteData } from '@/servers/http'
import { api } from '@/servers/api'
import { Dialog, Space } from 'antd-mobile'

const Resume = () => {
    const { fileDetail, userInfo, getFileDetail } = store || {}

    /** 制作简历 */
    const viewResume = (bizCode: string, file: any) => {
        const { fileUrl } = file
        const { platform_access_token, mid_domain } = userInfo || {}
        let callbackUrl = encodeURIComponent(window.location.origin + `/#/archives/resume/choose`)
        window.location.href = `${mid_domain}/job-center/my-resume/resume-preview?token=${platform_access_token}&callback=${callbackUrl}&bizCode=${bizCode}&pdfUrl=${fileUrl}&hiddenBtn=1&openKey=`
    }
    /** 删除简历 */
    const deleteDialog = (id: string) => {
        Dialog.confirm({
            content: '是否删除',
            onConfirm: () => {
                deleteData(`${api.userBarriersById}${fileDetail.id}`, { detail_id: id }).then(() => {
                    getFileDetail()
                })
            },
        })
    }

    return (
        <div className={styles.container}>
            <div className={styles.resume_wrapper}>
                <div className={styles.resume_list}>
                    {fileDetail.detail?.map((item: any) => {
                        return (
                            <div key={item.id} className={styles.resume_item}>
                                <div className={styles.resume_title}>
                                    <span>{item.capacityName}</span>
                                    {item.fileUrl && (
                                        <Space className={styles.resume_make} style={{ '--gap': '12px' }}>
                                            <span className={styles.delete} onClick={() => deleteDialog(item.id)}>
                                                删除
                                            </span>
                                            <span onClick={() => viewResume(item.code, item)}>查看</span>
                                        </Space>
                                    )}
                                </div>
                                <div className={styles.resume_row}>
                                    {resumeTypeMap.get(Number(item.type))}
                                    {Number(item.type) !== 2 && (
                                        <>
                                            <span className={styles.line} />
                                            {formateMoney(item.minSalary)} ~ {formateMoney(item.maxSalary)}
                                        </>
                                    )}
                                </div>
                                <div className={styles.resume_row}>
                                    {item.cityName}
                                    <span className={styles.line} />
                                    {item.industryName}
                                </div>
                            </div>
                        )
                    })}
                </div>
            </div>
        </div>
    )
}
export default observer(Resume)
